package com.example.myapplication.ui.fragment;

import android.content.Intent;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.myapplication.R;
import com.example.myapplication.base.BaseLazyFragment;
import com.example.myapplication.base.BasePresenter;
import com.example.myapplication.bean.QuestionsBean;
import com.example.myapplication.presenter.QuestionsPresenter;
import com.example.myapplication.ui.activity.WebViewActivity;
import com.example.myapplication.ui.adapter.QuestionsAdapter;
import com.example.myapplication.view.QuestionsView;

import java.util.List;

/**
 * 这是问答
 */
public class QuestionsFragment extends BaseLazyFragment<QuestionsPresenter> implements QuestionsView {



    private RecyclerView rv;
    private QuestionsAdapter questionsAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getQuestionsData();
    }

    @Override
    protected void initView(View view) {
        rv = (RecyclerView) view.findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        rv.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));
        questionsAdapter = new QuestionsAdapter(getActivity());
        rv.setAdapter(questionsAdapter);
        questionsAdapter.setOnItemClickListener(new QuestionsAdapter.OnItemClickListener() {
            @Override
            public void OnItemClick(int position, List<QuestionsBean.DataBean.DatasBean> list) {
                Intent intent = new Intent(getContext(), WebViewActivity.class);
                intent.putExtra("like",list.get(position).getLink());
                startActivity(intent);
            }
        });

    }

    @Override
    protected QuestionsPresenter initPresenter() {
        return new QuestionsPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_questions;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }


    @Override
    public void setData(QuestionsBean questionsBean) {
        List<QuestionsBean.DataBean.DatasBean> datas = questionsBean.getData().getDatas();
        questionsAdapter.setList(datas);
    }
}